//
//  TestHelper.swift
//  ZipTool
//
//  Created by jerry on 2025/8/15.
//

import Foundation

#if DEBUG
struct TestHelper {
    
    static func createSampleArchive() {
        // 这个方法可以用于创建测试用的压缩包
        // 在开发和调试时使用
        
        let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
        let testFolder = documentsPath.appendingPathComponent("ZipToolTest")
        
        do {
            try FileManager.default.createDirectory(at: testFolder, withIntermediateDirectories: true)
            
            // 创建一些测试文件
            let testFile1 = testFolder.appendingPathComponent("test1.txt")
            let testFile2 = testFolder.appendingPathComponent("test2.txt")
            let subFolder = testFolder.appendingPathComponent("subfolder")
            
            try FileManager.default.createDirectory(at: subFolder, withIntermediateDirectories: true)
            
            let testFile3 = subFolder.appendingPathComponent("test3.txt")
            
            try "这是测试文件1的内容".write(to: testFile1, atomically: true, encoding: .utf8)
            try "这是测试文件2的内容".write(to: testFile2, atomically: true, encoding: .utf8)
            try "这是子文件夹中测试文件3的内容".write(to: testFile3, atomically: true, encoding: .utf8)
            
            print("测试文件已创建在: \(testFolder.path)")
            
        } catch {
            print("创建测试文件失败: \(error)")
        }
    }
    
    static func printSupportedFormats() {
        print("支持的压缩格式:")
        print("- ZIP: ✅ 完全支持")
        print("- 7Z: ✅ 完全支持")
        print("- TAR: ✅ 完全支持")
        print("- TAR.GZ: ✅ 完全支持")
        print("- RAR: ❌ 暂不支持")
    }
    
    static func validateArchiveFile(_ url: URL) -> Bool {
        guard FileManager.default.fileExists(atPath: url.path) else {
            print("文件不存在: \(url.path)")
            return false
        }
        
        guard FileTypeHelper.isArchiveFile(url) else {
            print("不支持的文件格式: \(url.pathExtension)")
            return false
        }
        
        print("文件验证通过: \(url.lastPathComponent) (\(url.archiveTypeDescription))")
        return true
    }
}
#endif